//
// Created by liuzelin3 on 2023/5/24.
//
#pragma once
#include "panda_export.hpp"

#include <map>
#include <list>
#include <cstddef>
#include <cstdint>

namespace Panda{
    class PANDA_EXPORT DataPool{
    public:
        void* malloc (size_t size);
        void free(void*ptr);
        ~DataPool();
    private:
        struct DataNode{
            void* pool = nullptr;
            void* list = nullptr;
            uint8_t data[];
        };

        struct DataList{
            explicit DataList(size_t size);
            ~DataList();
            DataNode* malloc(size_t size);
            void free(DataNode* node);

            std::map<void*,bool> ptrs;
            uint8_t * start = nullptr;
            uint8_t * end = nullptr;
            uint8_t * buff = nullptr;
        };
        std::list<DataList*> lists;
        size_t list_size = 1024*1024;
    };
}
